home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Draw / Sources / AlgnObFr.cpp next >
Encoding:
Text File  |  1995-11-08  |  9.3 KB  |  260 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                AlgnObFr.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "ODFDraw.hpp"
  11.  
  12. #ifndef DRAWPART_H
  13. #include "DrawPart.h"
  14. #endif
  15.  
  16. #ifndef ALGNOBFR_H
  17. #include "AlgnObFr.h"
  18. #endif
  19.  
  20. // ----- Framewrk Layer -----
  21.  
  22. #ifndef FWPUSHBU_H
  23. #include "FWPushBu.h"
  24. #endif
  25.  
  26. #ifndef FWRADIOB_H
  27. #include "FWRadioB.h"
  28. #endif
  29.  
  30. #ifndef FWCLUSTR_H
  31. #include "FWClustr.h"
  32. #endif
  33.  
  34. // ----- OS Layer -----
  35.  
  36. #ifndef FWRECSHP_H
  37. #include "FWRecShp.h"
  38. #endif
  39.  
  40. //========================================================================================
  41. // Runtime Info
  42. //========================================================================================
  43.  
  44. #ifdef FW_BUILD_MAC
  45. #pragma segment opfdraw
  46. #endif
  47.  
  48. //========================================================================================
  49. // CLASS CAlignObjectsFrame
  50. //========================================================================================
  51.  
  52. const ODID CAlignObjectsFrame::kOkButtonId = 0;
  53. const ODID CAlignObjectsFrame::kCancelButtonId = 1;
  54. const ODID CAlignObjectsFrame::kTopToBottomClusterId = 2;
  55. const ODID CAlignObjectsFrame::kLeftToRightClusterId = 3;
  56. const ODID CAlignObjectsFrame::kNoneId = 4;
  57. const ODID CAlignObjectsFrame::kTopEdgesId = 5;
  58. const ODID CAlignObjectsFrame::kCenterId = 6;
  59. const ODID CAlignObjectsFrame::kBottomEdgesId = 7;
  60. const ODID CAlignObjectsFrame::kDistributeSpaceId = 8;
  61. const ODID CAlignObjectsFrame::kSampleAlignmentId = 9;
  62.  
  63. //----------------------------------------------------------------------------------------
  64. // CAlignObjectsFrame::CAlignObjectsFrame
  65. //----------------------------------------------------------------------------------------
  66.  
  67. CAlignObjectsFrame::CAlignObjectsFrame(ODFrame* odFrame, CDrawPart* drawPart) :
  68.     FW_CFrame(odFrame, drawPart),
  69.     fConnection(this)
  70. {
  71.     fConnection.Connect();
  72. }
  73.  
  74. //----------------------------------------------------------------------------------------
  75. // CAlignObjectsFrame::~CAlignObjectsFrame
  76. //----------------------------------------------------------------------------------------
  77.  
  78. CAlignObjectsFrame::~CAlignObjectsFrame()
  79. {
  80. }
  81.  
  82. //----------------------------------------------------------------------------------------
  83. // CAlignObjectsFrame::CreateViewLayout
  84. //----------------------------------------------------------------------------------------
  85.  
  86. void CAlignObjectsFrame::CreateViewLayout(Environment* ev)
  87. {
  88. // ----- Create the Top to Bottom radio cluster
  89.  
  90.     FW_CRadioCluster* tbCluster =
  91.         FW_NEW(FW_CRadioCluster, (FW_TYPEID_FROM_TYPE(FW_CRadioCluster),
  92.                                  this, kTopToBottomClusterId, FW_CPoint(ff(10), ff(10)), FW_CPoint(ff(160), ff(120)),
  93.                                  "Top to Bottom", kNoneId));
  94.  
  95.     FW_CRadioButton* noAlign =
  96.         FW_NEW(FW_CRadioButton, (FW_TYPEID_FROM_TYPE(FW_CRadioButton),
  97.                                  tbCluster, kNoneId, FW_CPoint(ff(10), ff(10)), FW_CPoint(ff(155), ff(18)),
  98.                                  "None"));
  99.  
  100.     FW_CRadioButton* topAlign =
  101.         FW_NEW(FW_CRadioButton, (FW_TYPEID_FROM_TYPE(FW_CRadioButton),
  102.                                  tbCluster, kTopEdgesId, FW_CPoint(ff(10), ff(30)), FW_CPoint(ff(155), ff(18)),
  103.                                  "Align top edges"));
  104.  
  105.     FW_CRadioButton* centerAlign =
  106.         FW_NEW(FW_CRadioButton, (FW_TYPEID_FROM_TYPE(FW_CRadioButton),
  107.                                  tbCluster, kCenterId, FW_CPoint(ff(10), ff(50)), FW_CPoint(ff(155), ff(18)),
  108.                                  "Align centers"));
  109.  
  110.     FW_CRadioButton* bottomAlign =
  111.         FW_NEW(FW_CRadioButton, (FW_TYPEID_FROM_TYPE(FW_CRadioButton),
  112.                                  tbCluster, kBottomEdgesId, FW_CPoint(ff(10), ff(70)), FW_CPoint(ff(155), ff(18)),
  113.                                  "Align bottom edges"));
  114.  
  115.     FW_CRadioButton* distributeAlign =
  116.         FW_NEW(FW_CRadioButton, (FW_TYPEID_FROM_TYPE(FW_CRadioButton),
  117.                                  tbCluster, kDistributeSpaceId, FW_CPoint(ff(10), ff(90)), FW_CPoint(ff(155), ff(18)),
  118.                                  "Distribute space"));
  119.  
  120. // ----- Create the Left to Right radio cluster
  121.  
  122.     FW_CRadioCluster* lrCluster =
  123.         FW_NEW(FW_CRadioCluster, (FW_TYPEID_FROM_TYPE(FW_CRadioCluster),
  124.                                  this, kTopToBottomClusterId, FW_CPoint(ff(190), ff(10)), FW_CPoint(ff(160), ff(120)),
  125.                                  "Top to Bottom", kNoneId));
  126.  
  127.     noAlign =
  128.         FW_NEW(FW_CRadioButton, (FW_TYPEID_FROM_TYPE(FW_CRadioButton),
  129.                                  lrCluster, kNoneId, FW_CPoint(ff(10), ff(10)), FW_CPoint(ff(155), ff(18)),
  130.                                  "None"));
  131.  
  132.     topAlign =
  133.         FW_NEW(FW_CRadioButton, (FW_TYPEID_FROM_TYPE(FW_CRadioButton),
  134.                                  lrCluster, kTopEdgesId, FW_CPoint(ff(10), ff(30)), FW_CPoint(ff(155), ff(18)),
  135.                                  "Align top edges"));
  136.  
  137.     centerAlign =
  138.         FW_NEW(FW_CRadioButton, (FW_TYPEID_FROM_TYPE(FW_CRadioButton),
  139.                                  lrCluster, kCenterId, FW_CPoint(ff(10), ff(50)), FW_CPoint(ff(155), ff(18)),
  140.                                  "Align centers"));
  141.  
  142.     bottomAlign =
  143.         FW_NEW(FW_CRadioButton, (FW_TYPEID_FROM_TYPE(FW_CRadioButton),
  144.                                  lrCluster, kBottomEdgesId, FW_CPoint(ff(10), ff(70)), FW_CPoint(ff(155), ff(18)),
  145.                                  "Align bottom edges"));
  146.  
  147.     distributeAlign =
  148.         FW_NEW(FW_CRadioButton, (FW_TYPEID_FROM_TYPE(FW_CRadioButton),
  149.                                  lrCluster, kDistributeSpaceId, FW_CPoint(ff(10), ff(90)), FW_CPoint(ff(155), ff(18)),
  150.                                  "Distribute space"));
  151.  
  152. // ----- Create the sample alignment
  153.  
  154.     CSampleAlignmentView* sampleAlignment =
  155.         FW_NEW(CSampleAlignmentView, (FW_TYPEID_FROM_TYPE(CSampleAlignmentView),
  156.                                 this, kSampleAlignmentId, FW_CPoint(ff(10), ff(125)), FW_CPoint(ff(155), ff(75))));
  157.  
  158. // ----- Create the Cancel button
  159.  
  160.     FW_CPushButton* cancelButton =
  161.         FW_NEW(FW_CPushButton, (FW_TYPEID_FROM_TYPE(FW_CPushButton),
  162.                                 this, kCancelButtonId, FW_CPoint(ff(200), ff(180)), FW_CPoint(ff(60), ff(20)),
  163.                                 "Cancel"));
  164.     FW_CInterest cancelInterest(cancelButton, cancelButton->GetButtonPressedNotificationToken());
  165.     fConnection.AddInterest(cancelInterest, &CAlignObjectsFrame::HandleButtonPressed);
  166.     
  167. // ----- Create the OK button
  168.  
  169.     FW_CPushButton* okButton =
  170.         FW_NEW(FW_CPushButton, (FW_TYPEID_FROM_TYPE(FW_CPushButton),
  171.                                 this, kOkButtonId, FW_CPoint(ff(280), ff(180)), FW_CPoint(ff(60), ff(20)),
  172.                                 "OK"));
  173.     okButton->SetDefault(TRUE);
  174.     FW_CInterest okInterest(okButton, okButton->GetButtonPressedNotificationToken());
  175.     fConnection.AddInterest(okInterest, &CAlignObjectsFrame::HandleButtonPressed);
  176. }
  177.  
  178. //----------------------------------------------------------------------------------------
  179. //    CAlignObjectsFrame::Draw
  180. //----------------------------------------------------------------------------------------
  181.  
  182. void CAlignObjectsFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  183. {
  184.     FW_CFacetContext fc(ev, odFacet, invalidShape);
  185.  
  186.     FW_CRectShape::RenderRect(fc, GetBounds(ev), FW_kFill, FW_kWhiteEraseInk);
  187. }
  188.  
  189. //----------------------------------------------------------------------------------------
  190. // CAlignObjectsFrame::HandleButtonPressed
  191. //----------------------------------------------------------------------------------------
  192.  
  193. void CAlignObjectsFrame::HandleButtonPressed(const FW_CNotification& notification)
  194. {
  195.     const FW_CButtonPressedNotification& buttonPressedNotification =
  196.         (FW_CButtonPressedNotification&) notification;
  197.     
  198.     if (buttonPressedNotification.GetButtonId() == kOkButtonId)
  199.     {
  200.         // Get the data out of the controls and do the alignment
  201.     }
  202.     
  203.     GetPart()->CloseDialogWindowDeferred(GetWindow());
  204. }
  205.  
  206. //========================================================================================
  207. // CLASS CSampleAlignmentView
  208. //========================================================================================
  209.  
  210. FW_DEFINE_CLASS_M1(CSampleAlignmentView, FW_CView)
  211.  
  212. //----------------------------------------------------------------------------------------
  213. // CSampleAlignmentView::CSampleAlignmentView
  214. //----------------------------------------------------------------------------------------
  215.  
  216. CSampleAlignmentView::CSampleAlignmentView(const FW_CClassInfo& classInfo,
  217.                                                FW_CFrame* frame, ODID id,
  218.                                                const FW_CPoint& location,
  219.                                                const FW_CPoint& size) :
  220.     FW_CView(classInfo, frame, id, location, size)
  221. {
  222.     CheckForInitialize(classInfo);
  223. }
  224.  
  225. //----------------------------------------------------------------------------------------
  226. // CSampleAlignmentView::CSampleAlignmentView
  227. //----------------------------------------------------------------------------------------
  228.  
  229. CSampleAlignmentView::CSampleAlignmentView(const FW_CClassInfo& classInfo,
  230.                                                FW_CView* enclosure, ODID id,
  231.                                                const FW_CPoint& location,
  232.                                                const FW_CPoint& size) :
  233.     FW_CView(classInfo, enclosure, id, location, size)
  234. {
  235.     CheckForInitialize(classInfo);
  236. }
  237.  
  238. //----------------------------------------------------------------------------------------
  239. // CSampleAlignmentView::~CSampleAlignmentView
  240. //----------------------------------------------------------------------------------------
  241.  
  242. CSampleAlignmentView::~CSampleAlignmentView()
  243. {
  244. }
  245.  
  246. //----------------------------------------------------------------------------------------
  247. // CSampleAlignmentView::Draw
  248. //----------------------------------------------------------------------------------------
  249.  
  250. void CSampleAlignmentView::Draw(const FW_CViewContext& gc)
  251. {
  252.     FW_CPoint size = GetSize();
  253.     
  254.     FW_CRect rect(ff(0), ff(0), ff(50), ff(15));
  255.     FW_CRectShape::RenderRect((FW_CViewContext *) &gc, rect, FW_kFrame);
  256.     
  257.     rect.Set(size.x - ff(12), size.y - ff(30), size.x, size.y);
  258.     FW_CRectShape::RenderRect((FW_CViewContext *) &gc, rect, FW_kFrame);
  259. }
  260.